<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="StyleSheet" href="../css/jpetstore.css" type="text/css" media="screen"/>
</head>
<body>
<header th:replace="common/top"></header>
<div id="Content">
    <div id="BackLink">
        <a href="/catalog/view"><button type="button" class="btn btn-sm btn-primary">Return to Main Menu</button></a>
    </div>

    <div id="Catalog">

        <h2>Shopping Cart</h2>
        <form action="/cart/updateCartQuantities" method="post">
            <table>
                <tr>
                    <th><b>Item ID</b></th>
                    <th><b>Product ID</b></th>
                    <th><b>Description</b></th>
                    <th><b>In Stock?</b></th>
                    <th><b>Inventory</b></th>
                    <th><b>Quantity</b></th>
                    <th><b>List Price</b></th>
                    <th><b>Total Cost</b></th>
                    <th>&nbsp;</th>
                </tr>
                <tr th:if="${cart.numberOfItems == 0}">
                    <td colspan="8"><b>Your cart is empty.</b></td>
                </tr>

                <tr th:each="cartItem:${cart.cartItems}">
                    <td>
                        <a th:href="'/catalog/viewItem?itemId='+${cartItem.item.itemId}"
                           th:text="${cartItem.item.itemId}"></a>
                    </td>
                    <td th:text="${cartItem.item.product.productId}"></td>
                    <td th:text="${cartItem.item.attribute1}+${cartItem.item.product.name}"></td>
                    <td th:text="${cartItem.inStock}"></td>
                    <td th:text="${cartItem.item.quantity}"></td>
                    <td>
                        <input type="text" th:name="${cartItem.item.itemId}" th:value="${cartItem.quantity}">
                    </td>
                    <td th:text="'$'+${#numbers.formatDecimal(cartItem.item.listPrice,1,2)}"></td>
                    <td th:text="'$'+${#numbers.formatDecimal(cartItem.total,1,2)}"></td>
                    <td>
                        <a th:href="'/cart/removeItemFromCart?workingItemId='+${cartItem.item.itemId}"><button type="button" class="btn-sm btn-danger">Remove</button></a>
                    </td>
                    <td th:if="${cartItem.inStock!=true}" th:text="库存不足"></td>
                </tr>

                <tr>
                    <td colspan="7">
                        <label th:text="'Sub Total:$'+${#numbers.formatDecimal(cart.subTotal,1,2)}"></label>
                        <input class="btn btn-sm btn-success" type="submit" value="Update Cart">
                    </td>
                    <td>&nbsp;</td>
                </tr>
            </table>
        </form>

        <a th:if="${cart.numberOfItems > 0}" href="/order/newOrder">
            <button type="button" class="btn btn-success">Proceed to Checkout</button>
        </a>


    </div>
</div>
<footer th:replace="common/bottom"></footer>
</body>
</html>